473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Select and Onchange Event

2
I have 3 input text boxes to fill using values populated from my database.

I am using an onchange event to put my selection into the first input text box.

My problem starts when I try to add value to the second input box.

I loose the first value but the second remain.

How will I arrange for the onchange event to fire successfully three times?

Please see some of the codes below.

Expand|Select|Wrap|Line Numbers
  1. function useAjax_1()
  2. {
  3.   myrnd=parseInt(Math.random()*999999999999999);
  4.   var str=document.getElementById("pcode").value;
  5.  
  6.   var xmlhttp;
  7.  
  8.   if (str.length==0)
  9.   {
  10.     y1.innerHTML="" ;
  11.     return;
  12.   }
  13.   x1=document.getElementById("sch1");
  14.   y1=document.getElementById("sch11");
  15.   x1.style.background="yellow";
  16.  
  17.   if (window.XMLHttpRequest)
  18.   {    // code for IE7+, Firefox, Chrome, Opera, Safari
  19.     xmlhttp=new XMLHttpRequest();
  20.   }
  21.   else
  22.   {// code for IE6, IE5
  23.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  24.   }
  25.  
  26.   xmlhttp.onreadystatechange=function()
  27.   {
  28.     if (xmlhttp.readyState==4 && xmlhttp.status==200)
  29.     {
  30.       y1.innerHTML=xmlhttp.responseText;
  31.     }
  32.   }
  33.   var queryString = "?url=" + str ;
  34.      queryString += "&rnd=" + myrnd;
  35.  
  36.   xmlhttp.open("GET","schools.php" + queryString,true);
  37.   xmlhttp.send();
  38. }
  39.  
  40. function showtext(t)
  41. {
  42.   x1.value= t;
  43.   x1.value=x1.value.toUpperCase();
  44. }
  45. y1.innerHTML="";
  46.  
  47. </script>
----from the database

Expand|Select|Wrap|Line Numbers
  1. $j=0; 
  2. while($row=mysqli_fetch_assoc($result1))
  3. {
  4.   foreach($row as $sch_name => $value)
  5.   {
  6.     $rowcat1[$j]['sch_name']=$value;    
  7.   }
  8.   $j++;
  9. }
  10. echo "<select id='schsel1' name='schsel1' onchange = 'showtext(this.value)'>";
  11. for($j=0; $j < count($rowcat1); $j++)
  12. {
  13.   echo"<option value = '{$rowcat1[$j]['sch_name']}'> 
  14.   {$rowcat1[$j]['sch_name']}<br />";
  15. }    //sizeof($rowcat)
  16. echo "</select> <br />";
-------

Expand|Select|Wrap|Line Numbers
  1. <label for= "lblsch1">First Pick up School</label>
  2. <input id= "sch1" name="sch1" size = "58" maxlength = "85"
  3.  onclick = "useAjax_1()" <value=<? echo @$_POST['sch1']?>>
  4. <br />
  5.  
  6. <label for= "lbl_sch1">&nbsp;</label>
  7. <span id = "sch11" type = "text" size = "85" ></span>
  8. <br />
  9.  
  10. <label for= "lbl_sch1">Second School</label>
  11. <input id= 'sch2' name="sch2" size = "58" maxlength = "85"
  12. onclick = "useAjax_2()" <value = <?php echo @$_POST['sch2'] ?>>
  13. <br />
  14.  
  15. <label for= "lbl_sch1">&nbsp;</label>
  16. <span id = "sch22" type = "text"size = "40" maxlength = "65"></span>
  17. <br />
  18.  
  19. <label for= "lbl_sch1">Third School</label>
  20. <input id= 'sch3' name="sch3" size = "58" maxlength = "85"
  21. onclick = "useAjax(3)"<value = <?php echo @$_POST['sch3'] ?>>
  22. <br />
  23. <label for= "lbl_sch1">&nbsp;</label>
  24. <span id = "sch33" type = "text" size = "58" maxlength = "85"></span>
  25. <br />
Sep 13 '13 #1
2 2402
Dormilich
8,658 Expert Mod 8TB
the x1 in showtext() is undefined (x1 is a local variable of useAjax_1()).

are useAjax_2() and useAjax() defined anywhere?

the <label>’s for attribute must exactly match another element’s id.

<input>: invalid attribute <value
Sep 15 '13 #2
Olamy
2
Thanks for all your help. I have gone through the codes again and rewrote it all. The problem had been resolved.

Thanks again
Sep 24 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jack | last post by:
Hello, I wrote this code: <%@ Language=VBScript %> <% Response.Write "<SELECT id=Customer name=Customer onchange=""text152='abc'"">" Response.Write "<OPTION value=1>One" Response.Write...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
1
by: Jan Doggen | last post by:
Hello all, I have a SELECT like this (the 'alert()s are temporary): <FORM method="POST" action="/scripts/runisa.dll?OVB2.132964:PGSPLITVACAFMELDEN:1095144287.9159" id="hulpform"...
1
by: Steve | last post by:
hi all any body has any idea on how to fire onchange event of a pulldown menu with script. i need to trigger it so it when i select a certain option from script,the event handler is executed
2
by: onerobe | last post by:
Hi everyone. I have this bizarre problem and i am hoping someone can point me in the right direction. I have a group of form selects, and when one is changed it dynamically changes the content...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.