Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php and javascript and html

Status
Not open for further replies.

dendic

Programmer
Jan 19, 2003
106
US
I have a dropdown box created in php within html the value of the dropdown box is concatenated example: <?php echo $consignees['consigneename']; ?>
<?php echo "-"; ?>
<?php echo $consignees['city']; ?><?php echo ", "; ?>
<?php echo $consignees['state']; >
When I run this javascript to retrieve the text from the box I get a return but it's spread out like this:
ADM PROTEIN SPECIAL - DECATUR, IL

Should be like this: adm protein special-Decatur, il
Perhaps if I build a global variable at the time of the selection using the three fields the result would be correct(just a guess). I don't know how to do this even to test it.
Any method that works would be appreciated. I'm still a newbie and learning everyday. It seems easy but can't get a handle on it. If my dropdown was two columns (index and text) it works fine but because of the concatenated there is this issue.
My script is:
$("#consigneeBtn").on('click', function() {
varconsignee = document.getElementById('consignee').value;
varconsigneetext= $('#consignee').find(':selected').text();
document.getElementById("consigneename").value = varconsigneetext;
});

I'm attempting to retrieve the selected text for dropdown 'consignee' and putting it in different textbox named 'consigneename'
Thank you
 
So what you are saying is you want the dash - to not have spaces before and after it?

Well, its hard to pinpoint trh4e issue with your code looking liek that, which by the way is the opposite of concatenation.

Perhaps doing it a little more directly may work:

Code:
<?php echo $consignees['consigneename'] . "-" . $consignees['city'] . ", " . $consignees['state'];?>

No need to break in and out of PHP tags so much.

If that does not work, check your variables, as they may be containing the spaces you want to remove.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
If that does not work, check your variables, as they may be containing the spaces you want to remove.
If so, use trim() around the variables or map the array to do it automatically

Code:
array_walk($consignees, 'trim');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top