spearchilduser Posted March 22, 2012 Share Posted March 22, 2012 Hoi i have a php select box populated from a database , i also have a textbox now i want to user to either enter details in the textbox or select something from the selecvt box and auto populate the texbox, i did try it but the php didnt seem to liek to work with the js ? any help or if it is possible Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/ Share on other sites More sharing options...
premiso Posted March 22, 2012 Share Posted March 22, 2012 Why are you duplicating posts? Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330271 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 becuase i originally thought it was a php issue and have since found out it isnt so am posting in the relavany thread that ok > Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330273 Share on other sites More sharing options...
premiso Posted March 22, 2012 Share Posted March 22, 2012 Dunno, I am not staff. I was just asking Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330274 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 aw fair enuf any ideas on how to resolve the issue whilst your reading Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330275 Share on other sites More sharing options...
rythemton Posted March 22, 2012 Share Posted March 22, 2012 <select onchange="document.getElementById( 'inputbox' ).value = this.value;"> <!-- Options Here --> </select> <input type="text" id="inputbox" name="inputbox" /> Should work. I haven't tested it, though. Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330280 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 yer ive tried a little bit of code myself and come up with script type="text/javascript"> <select name="FavDestinations" onchange="document.theform.Customer_Destination.value=this.value"> <option></option> <?php $sql = mysql_query("SELECT * FROM favourite_destinations WHERE User_ID =$userid"); while($row = mysql_fetch_array($sql)){ $uid = $row["User_ID"]; $username = $row["Name"]; echo '<option value="'.$uid.'">'.$username.'</option>' ; } ?> </select> but if i end the script the drop box disapears as its a php dropbox so should i change document.theform to document.getElementById ? Vubut even if i do this can it be done on a php dropbox ? Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330282 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 im currently usign onSubmit="return isValid()" in the form tag too is this a issue ? Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330286 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 btw its just a function name that checks each box has an entry Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330287 Share on other sites More sharing options...
rythemton Posted March 22, 2012 Share Posted March 22, 2012 There should be no conflicts with the 'onsubmit' code. Try your way and/or my way of referencing the text field. There is more than one way to select DOM members. Yet another way of selecting the text field, but will only work if the input field is the next field, would be this code: this.nextSibling.value = this.value; Don't be afraid to try new things. Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330298 Share on other sites More sharing options...
spearchilduser Posted March 22, 2012 Author Share Posted March 22, 2012 no i tired it but it doesnt work :s the code that i showed u only other thign i can think of is if i set it up as a function but would i then say somethign like onchange. ( fucntionname()). or is there soemthign wrong with the code i showed earlier ? function i think would work : { x = document.getElementById("Customer_Destination"); y = document.getElementById("FavDestinations"); x.value = y.options[y.selectedIndex].text; } Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330299 Share on other sites More sharing options...
rythemton Posted March 22, 2012 Share Posted March 22, 2012 I thought you could get the value of selected options by just asking for the value, but I guess not. Your function should work, you can call the function by putting it in the quotes for the onchange. My codes should work if you replace the 'this.value' to 'this.options[ this.selectedIndex ].value', or if you didn't set any values in the options, you can change the 'value' to 'innerHTML' or 'text'. Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330347 Share on other sites More sharing options...
spearchilduser Posted March 23, 2012 Author Share Posted March 23, 2012 hi i now have <script language="javascript" type="text/javascript"> { x = document.getElementById("Customer_Destination"); y = document.getElementById("FavDestinations"); x.value = y.options[y.selectedIndex].text; } as a function then <select name="FavDestinations" document.theform.Customer_Destination.value='this.options[ this.selectedIndex ].value'> <option></option> <?php $sql = mysql_query("SELECT * FROM favourite_destinations WHERE User_ID =$userid"); while($row = mysql_fetch_array($sql)){ $uid = $row["User_ID"]; $username = $row["Name"]; echo '<option value="'.$uid.'">'.$username.'</option>' ; } ?> as the drop box witht he onchange() function running thsi isnt fillign out a textbox is there any errors that can be seen with the code im more of php than javascript so there may be Quote Link to comment https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.