JavaScript - Javascript Variable To Form Hidden Variable's Value
Hi!
I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document. This is my JavaScript Code: Code: function WriteContactFormStatement1 () { var ContactFormValue = ref2; document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '" />'); } var WriteContactFormStatement = WriteContactFormStatement1 (); And at the end of my form, before the submit button, I have the following code: Code: <!-- START -- Javascript to print the statement for UReferrersName --> <script language="JavaScript" type="text/JavaScript"> //WriteContactFormStatement(); document.write (WriteContactFormStatement); </script> <!-- End -- Javascript to print the statement for UReferrersName --> When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button ..... Please help !... - Xeirus. Similar TutorialsI really thought this would work, a user goes to a page, selects a value from a select box then clicks a link to run a report using that hidden variable as a parameter. I am attempting to place the value in the URL to pass it. I'm sure the javascript is working, and maybe it's the HTML I've messed up - not sure. Here is the javascript (the alert does return the correct value): Code: function OnChangeDay() { //assign the day id to the hidden variable $day x=eval(document.getElementById("day_loc_id_select").value) if(x) { document.getElementById("test_day_id").value=x; } else { document.getElementById("test_day_id").value=0; } // test alert(document.getElementById("test_day_id").value) } Here is the calling HTML: Code: <input type="hidden" name="test_day" id="test_day_id" value=""> <select name="day_loc_id" id="day_loc_id_select" onchange="OnChangeDay()"> <option></option> <?= form_options($day_loc_options) ?> </select> And here is the HTML that should send the value, but I get day= (nothing) Code: <a href='/depts/edoptions/excel_extract.php?ex=2&day=<? echo $test_day ?>'>SLIP Data to Excel</a> Can anyone point out where I've messed up? Thanks Hi, I wanted to know if there is way in Javascript to send a hidden variable to an external URL without actually submitting to the URL? Code below is what I intend to do. I want to use an image to do an onClick event and send the name to an external URL without actually doing a submit. Code: <td width="25"> </td> <input type="image" src="images/btn_Activate.gif" onClick="window.location.href='www.abc.com'"> <input type="hidden" name="name" value="<% = name %>"> </td> Thanks. Jeeten. Hi all, I'm having some trouble with the this... I have a PHP based calendar where the cells will change color depending on the number of clicks.. this all works fine, but is pointless if I can't send the outcome along in an email. I can do this with PHP but first need to get the values into a hidden field. This is what I have: Code: <script type="text/javascript"> function countClicks (obj){ if (!obj.count) { obj.count = 0; } obj.count++; if (obj.count > 4) {obj.count = 1}; if(obj.count == 1){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#66CC33'; obj.parentNode.style.backgroundColor='#66CC33'; document.getElementById("availability").value='Available'; } if (obj.count == 2){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FF0000'; obj.parentNode.style.backgroundColor='#FF0000'; document.getElementById("availability").value='Not Available'; } if (obj.count == 3){ obj.style.color='#FFFFFF'; obj.style.backgroundColor='#FFCC33'; obj.parentNode.style.backgroundColor='#FFCC33'; document.getElementById("availability").value='Working'; } if (obj.count == 4){ obj.style.color='#000000'; obj.style.backgroundColor='#FFFFFF'; obj.parentNode.style.backgroundColor='#FFFFFF'; document.getElementById("availability").value='Not Set'; } } </script> and... Code: echo "<input type=\"hidden\" name=\"availability\" id=\"availability\" value=\"\">"; All I'm trying to do is populate value with either 'available', 'not available', 'working' or 'not set'... however, it is worth noting that each cell may have a different value, e.g. 1 cell might be working while the other is not available... so i need to pass the values of all the cells. Can anyone help me out here. Many thanks, Greens85 hi guyz i do have a problem in passing javascript variable to <input type=hidden value=""> here's my code: <?php while ($row = mysql_fetch_array($result)) { ?> <script type="text/javascript"> function viewcodec(){ var randomValueCodec = randomString(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); document.getElementById('commentMarkCodeCompCodec-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; document.getElementById('commentMarkCodeComp-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; } </script> <form action="" method="post" name="postsForms"> <div class="commentBox" align="right" id="commentBox-<?php echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>> <input type=text id="commentMarkname-<?php echo $row['p_id'];?>" name="commentmarkname" class="commentMarkname" size="35" maxlength="20"> <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" name="commentmark" cols="60"></textarea> <input type=text id="commentMarkcode-<?php echo $row['p_id'];?>" name="commentmarkcode" class="commentMarkcode" size="35" maxlength="20"> <br clear="all" /> <span id='commentMarkCodeCompCodec-<?php echo $row['p_id'];?>'><b><script type="text/javascript">viewcodec();</script></b></span> <input type="hidden" id="commentMarkCodeComp-<?php echo $row['p_id'];?>" name="commentMarkCodeComp" value=""> <br clear="all" /> <br clear="all" /> <a id="SubmitComment" style="float:right" class="small button comment"> Comment</a> </div> </form> <?php } ?> Hello I have a piece of javascrip that refreshes the page: ---------- Code: <script type="text/javascript"> <!-- Begin function reFresh() { location.reload(true) } /* Set the number below to the amount of delay, in milliseconds, you want between page reloads: 1 minute = 60000 milliseconds. 2 minutes = 120000 milliseconds 5 minutes = 300000 milliseconds*/ window.setInterval("reFresh()",20000); // End --> </script> -------- I am new to javascript and wanted to use an html options menu in order to be able to choose the refresh interval: Code: <SELECT NAME="refreshtime"> <OPTION VALUE="60000">1 min</option> <OPTION VALUE="120000">2 min</option> <OPTION VALUE="180000">3 min</option> <OPTION VALUE="240000">4 min</option> </SELECT> I know that I have to pass a variable to the function. I have tried several variations but none have worked. I have mostly received a "done with errors" warning. Any help would be appreciated. Thanks Zam I've been having a hard time with this and was hoping someone here would take a little pity and render me a great service. I'm using a javascript to get the user's timezone and am trying to pass the response to an input field in a php form. With a great deal of trial and error I got a demo working to a point but I'm stuck. Here's what works now: Code: <p id="timezoneInformation" style="text-align: center;">click here</p> <script src="jstz.js"></script> <script> var container = document.getElementById("timezoneInformation"); var showTimezone = function () {container.textContent = jstz.determine().name();}; container.addEventListener("click", showTimezone); </script> jstz.js is from Automatic timezone detection using JavaScript The example above is as far as I've gotten. I would like to send the results to a form field to submit to the server. It's probably a lot easier than I'm making it out, but I've had little success and would welcome any help. Thank you. I have used php with forms but can I do easy form to java vars? I saw one snippit of code that did it when I was newer but did not understand it. what is the way you usually do this? so i have this code i am working on(this is a dumbed down version of it) Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#Submit").click(function(){ for (i=0;i<=50;i++) { $.ajax({ url:"process.php", type:"get", data:$("form").serialize(), success:function(response){ var obj = jQuery.parseJSON( response ); var success = obj.success; var actionsNumber = obj.number; $("#result").html('There have been '+actionsNumber+' loops completed'); } }) } }) }) </script> </head> <body> <form action="" method="post"> <p> <label><strong>Number of Loops</label> </p> <input name="count" type="text" value = "1"/> </p> <p> <input id="Submit" type = "button" value = "Send"> </p> </form> <p id="result">There have been 0 loops completed</p> </body></html> so you see this for loop for (i=0;i<=50;i++) I want it to be able to be like for (i=0;i<=count;i++) so that it will loop the number of times inputted also(though i dont know if this is something that i need to use js for) On my full code there are other textboxes that need to be sent to process.php each time that it is run. How can i achieve this? also before anyone asks i have googled this and searched around yet i havent been able to figure this out, everything i have tried hasnt worked and here is the process.php PHP Code: <?php session_start(); // process the form data here //::::::::: // if(!isset($_SESSION['number'])){ $_SESSION['number'] = 0; } $number = $_SESSION['number']++; // output json response echo'{"success":"true","number":"'.$number.'"}'; ?> Hi all, I am new to JS and usually learn by studying code posted online and modify it to have it do what I need. Recently, I used a totaling plugin for an online ordering form which does the below: item1 qty(user input text) * preset price = total price item2 qty(user input text) * preset price = total price item3 qty(user input text) * preset price = total price -------------------------------------------------------- grand total -------------------------------------------------------- The JS code which passes the grandTotal variable is as below: Code: function ($this){ // sum the total of the $("[id^=total_item]") selector var sum = $this.sum(); $("#grandTotal").text( // round the results to 2 digits "₹" + sum.toFixed(2) ); } The problem I have is the above grandTotal displays the final value when put into a table like below: Code: <td align="right" id="grandTotal"></td> But I am unable to make it work by passing it into a variable within the form fields. I would like to do something like this: Code: <input type="text" name="grandTotal" id="grandTotal" readonly="readonly" /> Can somebody please help me fix this? Any help will be greatly appreciated. Thank you. hi , i am trying to pass a javascript variable into URL ..but not getting the value.. var newID = 2; row.insertCell(6).innerHTML = "<a href=Update_Gate.cfm?GateIdVar=newID>Edit Gate</a>"; i am getting "newID" in Update_Gate.cfm page ... i want to pass this javascript variable in url and read it on the other page as form field value any help !! Can anyone tell me of how to take or assign a javascript variable into php.
I'm a long time lurker on here just barely created an account to ask this question. I work at a call center, and we use different webapps to fill out tickets. One I've used for a long time allows dynamically updating forms with javascript. I have a whole bunch of bookmarked javascript injections like: Code: javascript:if((top.detail.findObj('X31').value="Inquiry")!=""); That code will fill out most everything in that ticket, leaving me to fill in the details. I have one of those for all of the most common tickets, and can create and finish a ticket in less than 30 seconds when it takes others 3-4 minutes. I recently switched to a different system and I'm having trouble with my code. I'm a noob at javascript for sure, but I'm not new to programming. Anyway any pointers would be nice. The system we use doesn't allow me to see the source... I'm not sure how to explain it. It loads everything in a frame. In chrome I can right click then inspect element and get the ID but it the above javascript doesn't work. Examples: Old app source ex: Code: <label for="X31">Category:</label> was all i needed new app(before the body code is just code for the login form, etc): Code: <body onLoad="startit()" onUnload="stopit()"> </body> <div align="center" valign="center" id="LoadMessageID" style="position: relative; top:40%; color:#0069A5; font-size:100% ;"> <img src="/arsys/shared/images/Progress_NonModal-circle.gif" alt="wait image"/> Loading... </div> </html> formloader: Code: <form name="form1" action="/arsys/forms/bmcitsm/HPD:Incident+Management+Console/Default+User+View+(Support)/?cacheid=a22a36a8" method="post"> example of inspect element in chrome (something i want to change with javascript injection): Code: <input id="arid301602600" type="text" class="text " style="top:0; left:0; width:225; height:21;" readonly=""> Hi, I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... Hello I have a php page in which I declared a js variable... right at the top of the page... <script type="text/javascript"> var tester = 0; </script> Later in the page I test this variable... <script type="text/javascript"> if (tester==1){ do some stuff!! } </script> But I keep getting an error variable _tester undefined Am I missing something obvious... I am new to js... but this seems really straightforward I don't know how I should do ? Quote: <html> <head> <script type="text/javascript"> function add(a,b){ y=a+b return y } var aaa = add(one,two) //one needs to get somehow get the value of yil, in this case 10 var one = function reas(){i=10;if(i<10){yil = 15}; else{yil = 10; yil = one;}; var two = 20; document.write(y) </script> </head> </html> also why doesn't this work? Quote: <html> <head> <script type="text/javascript"> function adder(a,b){ var k=a+b; return k } var hes=adder(5,kol); kol=40; alert(hes); </script> </head> </html> you cannot have variables in callback functions? Hi, is it cool/possible to use a php variable inside the javascript ? i have this hidden html form field PHP Code: <?php $unique = md5(uniqid()); ?> <input type="hidden" name="unique" id="<?php echo $unique; ?>" value="" /> then i have this javascript PHP Code: var hiddenfield = document.getElementById('<?php echo $unique; ?>'); hiddenfield.value = new Date().getTime(); LOL it doesn't work, can somebody help me please ? SOLVED I am trying to use a php variable in javascript. At the moment I am using a fixed variable PHP Code: $articleID = 5; Then outputting it to the page to declare a javascript variable Code: var articleid = "<?php echo $articleID; ?>"; Then trying to us it within a string "FlashVars", "fileURL=../uploadedfiles/+ articleid + .gpx&key=ABQIAAAAOQBC......... Can anyone tell me what I am doing wrong? I am not very used to Javascript and perhaps I am going about it totally the wrong way. Help! Gordon I get the screen resolution with this script: <SCRIPT language="JavaScript"> <!-- height = screen.height; width = screen.width; document.write(width + "x" + height); var x = ( width + "x" + height); //--> </SCRIPT> Now I have some links below and I want to use bold if the link has the same screen resolution: <a href="page1">800x600</a> <a href="page2">1024x768</a> <a href="page3">1680x1050</a> <a href="page4">1920x1200</a> Supposing my screen resolution is 1920x1200, the result should be: 800x600 1024x768 1680x1050 1920x1200 How do I do that? Thx!! Is it possible to pass the value of a javascript variable through src? For example, instead of... <script type="text/javascript" src="/myfolder/myjsfile.js"></script> ...could I have something like... <script type="text/javascript" src=JS VARIABLE VALUE></script> What would be the syntax for this? Is it even possible? Thank you! |