JavaScript - Copy Input Value Array To Another Input Value Array On Submit
Hi,
i have an input value array for customer ids, i also need to make a copy of that array into another input element on submit to use for another process. So far here is what i have come up with regarding the js the current html is this Code: <!-- original input --> <input id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $commissions[$i]['id'];?>" onclick="isChecked(this.checked);" type="checkbox" /> <!-- this is new html input which is outside the $i loop that i need a copy of cid[] stored on submit <input type="hidden" name="ids[]" onsubmit="valueTovalue();" /> <!-- here is the js so far --> <script type="text/javascript"> function valueTovalue() { var valin = document.adminForm.cid.value; //cid is the array cid[] document.adminForm.ids.value = valin; //copy the array to the new input element array ids } </script> so basically if they click 1 cid then ids will also show 1, if they click all cid then ids will show all as well. will that work the way i have it, am i even close here.. thanks update: what i have seems to work fine for text values or string values but not for arrays, what am i missing that it wont copy an array? Array ( [cid] => Array ( [0] => 1 ) [task] => remarksonly [remark] => hhhyyy [boxchecked] => 1 [ids] => Array ( [0] => ) ) am i getting closer lol Code: function valueTovalue() { var valin = cid.concat; document.adminForm.ids.value = valin.concat; return(true); this has to be close i hope Code: document.adminForm.ids.value = [].concat(document.adminForm.cid); Similar TutorialsHi I have problem to manipulate my form with array. I want to copy my input from one input to other input but it didnt work. i did explore the usage of document.myForm.feed[3].value but it gave me error. Pleaseee help? Thanks script sample: <form name=myForm> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=feed[] onBlur=duplicate(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> <input name=copier[] onBlur=sendback(this)> </form> <SCRIPT> function duplicate(info) { //this function should copy 'info' to copier input //with the same element location //eg: feed[3] will copy to copier[3], feed[5] will copy to copier[5] //(can be any element insert by user) // the task would be: // 1. to get which element number has been inserted // 2. to get the origin text value // 3. to write the same element position for copier } function sendback(info) { //this function should copy 'info' to feed input //with the same element location //copier[2] will copy to feed[2], copier[3] will copy to feed[3] //(can be any element insert by user) } </SCRIPT> Hello everyone I am trying to receive the output of an array from a text input here is the code that I am attempting to do but it is not displaying the output January Here is the code example [CODE] <html> <script type ="text/javascript"> <!-- function coms(str){ var myArray = new Array(); myArray[0] = ["January"]; var index = 0; for(var i = 0; i < myArray.length; i++){ index; if(myArray[i] == "January"){ index i; } if(str.length == myArray[i]){ document.write(str); } } } </script> <body> <form> Panel:<input type="text" name="panel" onkeyup="coms(this.value)" /> <div id="read"><p>Data is displayed here</p></div> </form> </body> </html> [CODE] Any tips to make this possible are welcome thank you kindly hello, I have a text input box where users can input values separated by a line break. What I need to do is to take those values and put them all into an array once they hit "submit". I can do this one line at a time, but I would like to be able to do it all in one hit. Can it be done in javascript? thanks in advance... i have tried searching the forums for help but really am getting no where. i am trying to call an array item from an input box. the input is all numbers. the arrays are v + numbers. i cannot seem to figure out how to get the item from the array. eg Code: var v00501 = ["HOLTSVILLE,I R S SERVICE CENTER","NY","631","-5","Y"] var v00544 = ["HOLTSVILLE,IRS SERVICE CENTER","NY","631","-5","Y"] var v00601 = ["ADJUNTAS,JARD DE ADJUNTAS,URB SAN JOAQUIN","PR","787/939","-4","N"] function pop() { var zipv = "v" + myform.Zip.value +"[0]"; alert(zipv); } or Code: function pop() { alert(pop1()); } function pop1() { return "v" + myform.Zip.value +"[0]"; } so for this if the user typed in 00501 i get v00501[0] no matter what i try. i want HOLTSVILLE,I R S SERVICE CENTER to be returned or whatever item i am calling for. this all has to be on client side as i dont have server access so the zip codes are all set up as arrays in a seperate file. i really dont know alot about javascript but i am learning. any help on how i can accomplish this would be appreciated. the title kind of sums it up... if I have an array of equations (I'm guessing they should be strings but they don't have to be) and a user-defined variable can that variable be used for the "x" in the equations? I already did the easy part ... Code: <!DOCTYPE html> <html> <head> </head> <body> <input onkeyup="solve(this.value)" /><br> <input id="box0" /><br> <input id="box1" /><br> <input id="box2" /><br> <script type="text/javascript"> var equations=["(x*9/5)+32","x+273.15","x-50*(8/13)"] function solve(val){ for (var i = 0; i < equations.length; i++) { document.getElementById("box"+i).value= //ummm... } } </script> </body> </html> Hi, I'm struggling with all this DOM stuff so I hope someone can help. I have a form with multiple input fields and I'm trying to identify the specific input field that is in focus so that I can display a relevant status bar message. I have a message array with various entries in it and I'm calling a showStatus() function with an onfocus function from the form itself e.g. The code in the input form = Code: <input type="text" name="first" size="31" maxlength="20" class="entry" onfocus="showStatus()"/> The showStatus() function so far is = Code: function showStatus() { var message = ['Please provide your First Name.', plus loads of other properley formatted status messages......] var x=document.getElementById().focus(); window.status = message[x]; } I'd like to access the array variable of the item that is in focus not only for the message but also for an onblur function to validate input. Any ideas? My thanks R Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks Hi, i've got a calculator/quotation script i've made. Once the calculation is complete, i want the user to click a button which will copy some of the field data to new fields for printing. This is fine and i can do easily, however i then want the user to be able to reset the form and do another calculation, click the same button and it copy the new data to new fields too. So in effect you end up with all of your calculations listed somewhere for printing. how would i attempt this? any help appreciated Hi, In a nutshell,can anyone tell me how to copy a 2d (two dimensional ,2 dimensional) php array to 2d javascript array?I would be obliged if anyone can provide me a method of doing that OR I have written a code to copy a 2d php array to a 2d javascript array.It is working but there is one problem(please see the following).Can anyone tell me what I am doing wrong here? The 2d php array is $quest[100][6] and the 2d javascript array is questions[100][6] . I have written the javascript code inside the <?php....?> itself using echo "<script language="javascript" type="text/javascript">.......</script>; Now ,inside the javascript,when I try to copy the 2d php array to the 2d javascript array using the following method it works questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1]= ["<?php echo join("\", \"", $quest[1]); ?>"]; ... and so on However, if I try to do the same using the following method it does not work for (var i= 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } Why is that?What mistake am I making?Any help will be deeply appreciated.Thanks -----------------------------THE CODE------------------------------------ <?php Access database and store result of mysq_query in $result....... $result = mysql_query($query); for ( $count = 0; $count <= 99; $count++) { $quest[$count]=mysql_fetch_array($result,MYSQL_NUM);; } echo "<script language="javascript" type="text/javascript"> var questions = new Array(100); for (var i = 0; i <100; i++) { questions[i] = new Array(6); } /*The following method of copying 2d php array to 2d javascript array is not working for ( var i = 0; i <= 99; i++) { questions[i]= ["<?php echo join("\", \"", $quest[i]); ?>"]; } */ /*The following method ,however,is working*/ questions[0]= ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"",$quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"",$quest[2]); ?>"]; ....and so on </script>"; mysql_close($db_server); ?> Hi, Here is a working code to copy 2d php array to 2d javascript array. Code: <html> <head> <?php for($i = 0; $i < 3; $i++) { for($j = 0; $j < 2; $j++) {$quest[$i][$j] = $i*10+$j;} } ?> <script type="text/javascript"> var questions = new Array(3); for (var i = 0; i < 3; i++) { questions[i] = new Array(2); } questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; document.write(questions[0][0] + "<br />"); document.write(questions[0][1] + "<br />"); document.write(questions[1][0] + "<br />"); document.write(questions[1][1] + "<br />"); document.write(questions[2][0] + "<br />"); document.write(questions[2][1] + "<br />"); </script> </head> </html> Now,here's the thing.Notice these lines in the code questions[0] = ["<?php echo join("\", \"", $quest[0]); ?>"]; questions[1] = ["<?php echo join("\", \"", $quest[1]); ?>"]; questions[2] = ["<?php echo join("\", \"", $quest[2]); ?>"]; I would like to put these lines in a loop,something like for (var i = 0; i < 3; i++) { questions[i] = ["<?php echo join("\", \"", $quest[i]); ?>"]; } But even after a lot of efforts I am unable to do so,what am I doing wrong?Thanks I have a very small script that simply displays a search box and redirects a user to a URL if they enter 29401 or 29455, else they go to a default page. The script works fine, but I cannot figure out how to make value="enter a zip code" in the input box so that it disappears when you click in the box. I also can't get the form to submit by pressing enter, you have to click "check". I can get all this working in straight HTML but the same won't work w/ javascript. Any help please? <SCRIPT LANGUAGE="JavaScript"> function zipValidate(){ val = document.zipForm.zip.value; switch(val){ case "29401": case "29455": document.location = 'http://www.gohere.com'; break; default: document.location = 'http://www.or-go-here.com'; break; } } </SCRIPT> <form name="zipForm" id="zipForm" method="post" action=""> <input name="zip" type="text" id="zip" maxlength="5" /> <input name="zipButton" type="button" id="zipButton" value="Check" onclick="zipValidate()" /> </form> Hello there, I want to build a form which invokes an ajax-function and therefore the page shouldn't reload. The problem is I don't want to avoid the autocompletion of the browser. But to save the input i have to submit the form regularly, which means 'onSubmit="return false;"' doesn't work. Is there any possibility or is this technique just impossible? Thx for reading and thinking about it! This is the current code, which works fine, but the browser doesn't save the (non-)submitted input. (The submit will be invoked by the "getSuggests()"-function.) Code: <form id="mytaste-selection" name="mytaste-selection" autocomplete="on" onSubmit="return false;"> <fieldset> <legend> Search </legend> <div style="padding: 0px 0px;"> <label class="standard">Artist:</label> <input id="mytaste-artist" name="mytaste-artist" class="standard text" type="text" autocomplete="on"/> <label class="standard">Title:</label> <input id="mytaste-title" name="mytaste-title" class="standard text" type="text" autocomplete="on"/> </div> <div class="button" onclick="getSuggests(urlEncode(getElementById('mytaste-artist').value),urlEncode(getElementById('mytaste-title').value),(getElementById('top').checked)?'top':'similar');"> Search </div> <div> <label class="standard">Top Tracks</label> <input class="standard radio" name="method_type" id="top" type="radio" checked="checked"/> <label class="standard" style="margin: 2px 2px 2px 20px;">Similar Tracks</label> <input class="standard radio" name="method_type" id="similar" type="radio"/> </div> </fieldset> </form> PS: If anything isn't clear please inform, if you also think that this issue is tricky, just answer with "Tricky" PPS: you can have a look at the page at http://mytaste.alitility.com This is probable very easy, I've tried with normal html and am unable to get my head around it. I would like to in some way replicate how a web browser works. I have a form entry field with a submit button at the top of the page. Under that I have an iframe. I copy the url http://www.bbc.co.uk into the entry field, click submit and the iframe updates with the website. Have looked around and haven't found anything similar. Code so far.... <form target="myURL"> <input type="text" name="goTo"> <input type="submit" name="submit" value="submit"> </form> <iframe src="" name="myURL" border="0" frameborder="0" width="768" height="354"></iframe> Thanks in advanced. Death = $Mill Below is a script I found at http://bytes.com/topic/javascript/an...cookie-problem The idea is a like button, like on fb, in a form which updates a db field I can use to display the number of likes, and my goal is to disable the like button for the rest of the session, or a day, or whatever. This script disables it onclick, the problem is I can't figure out how to get it to submit the form as well. I have found it does submit if the input type is 'submit', but then it doesn't call the disable function. I tried writing another function to submit the form but no go. Code: <html> <head> <title>Vote Button</title> <script type="text/javascript"> function checkForVote() { // If there is a cookie... if(document.cookie != "") { if(getCookie("voted") == 1) { // Disable the button again if user already voted. disableButton(); } } } function disableButton() { var submitvote = document.getElementById("submitvote"); submitvote.disabled = true; submitvote.value = "You Already Voted."; } function setCookie(name, value, days) { if(days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires = " + date.toGMTString(); } else { var expires = ""; } document.cookie = name + "=" + value + expires + "; path=/"; // Disable the button as soon as the user clicks it. disableButton(); } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); } } return null; } </script> </head> <body> <form name="voteform" id="voteform" action="foo.php" method="post"> <input type="button" name="submitvote" id="submitvote" onclick="setCookie('voted', 1, -1);" value="Submit Vote"/> </form> </body> <script type="text/javascript"> // Run checkForVote() at end of document so that form and contents can be referenced window.onload = checkForVote(); </script> </html> It seems like it should be simple, but I don't see what I'm missing. Right now, the search button displays directly under my input field. I've gone through the CSS, but can't figure out where my code is forcing the button onto its own line. What am I missing? How can I bring it up to the same line?? Code: <form role="search" method="get" id="searchform" action="http://www.centerpie.com/" > <div> <input type="text" value="" maxlength="100" name="s" id="s"><input type="submit" id="searchsubmit" value="Search"> </div> </form> Hate to ask this as I know it's an easy one but surprisingly Google turns up no clear/simple answers! I'm modifying some old code and am not JS programmer (I'm a PHP programmer) and this is driving me nuts. The existing code makes sure that when the form is submitted that there isn't a missing value. There's also some hidden input values. The JS starts out function checkform(orderform) and the form tag includes onsubmit="return checkform(this);"> I can add an alert to the form to see varius input values, such as a hidden value for the input name 'description' I can use: alert (orderform.description.value) Eazy peazy. However the form has two different input type=image buttons now and I need to do some branching in the JS depending on which image button they press. I recall IE had an issue where it only sends the x and y coordinates So I figure an easy to determine which image button was pressed is just check to see if the x or y value for each button is non-zero. But I can't for the life of me figure out how to access the value. Example: alert (orderform.button1.x.value) doesn't work. Can someone refresh my memory or suggest an entirely different method for detecting which image button was used to submit a form? THanks in advance! I am thinking this should be fairly easy but yet I am not getting far. I want to have a form with a single text imput field for a zip code. Depending on which zip code the user enters will determine which url they will be sent to. If they enter a zip code which is not in the script, they would be sent to a default url. I am also assuming this can be accomplished with javascript. Any help is greatly appreciated. I have a problem with adding new inputs to a form (if and when required), Internet Explorer is fine but in Firefox if any previous input fields are filled when the more button is clicked they get reset to blank. JS: Code: fields = 0; function addInput() { if (fields != 100) { document.getElementById('input').innerHTML += "<input type='text' name='input[]' size='30' />"; fields += 1; } else { document.getElementById('input').innerHTML += "<br />Maximum 100 fields allowed."; document.form.add.disabled=true;} } form: Code: <form action="index.php" method="post"> <div id="input"> <input type="text" name="input[]" size="30" maxlength="15" /> </div> <!-- button --> <div id="more"> <input type="button" onclick="addInput()" name="add" value="More" /> </div> <!-- // button --> <input type="submit" name="submit" value="Submit" /> </form> as usual any help is appretiated .. Hi, i want to set an input value to the same value as the input selected from another input on the same form so when the user selects input 1 i want the hidden input2 to get the same value im guessing i use onsubmit because its hidden so there wont be a focus or blur this would be part of the input Code: onsubmit="(this.value = this.othervalue)" othervalue being the other input name="othervalue" is that the correct syntax |