INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

php and javascript and html

php and javascript and html

(OP)
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

RE: php and javascript and html

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

RE: php and javascript and html

Quote:


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'); 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close