Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330282
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330298
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330299
Share on other sites

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'.

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330347
Share on other sites

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 :(

Link to comment
https://forums.phpfreaks.com/topic/259510-help-please/#findComment-1330448
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.