Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve a textbox value using JQuery? [duplicate]

Tags:

jquery

Possible Duplicate:
How do I get the value of a textbox using jQuery?

on form submit, i am trying to grab the value of the textbox below and shove it in an url

<input type="text" style="width: 300px" id="fromAddress" name="from" value="" />&nbsp;

here is my jquery code:

<script type='text/javascript'>
     $(document).ready(function() {

         $(":submit").click(function(e) {

             var from = $("input#fromAddress").text;
             $('div#printdirec').html('<a target="_blank" href="http://maps.google.com/addr=' + from + '&daddr">Print Directions</a>');

         });

     });
</script>

when i look at the URL, it doesn't have the correct from address.

like image 287
leora Avatar asked Aug 24 '09 01:08

leora


People also ask

How to retrieve textbox value in jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

How to check duplicate values in table jQuery?

var contents = {}, duplicates = false; $("#yourtableidhere td"). each(function() { var tdContent = $(this). text(); if (contents[tdContent]) { duplicates = true; return false; } contents[tdContent] = true; }); if (duplicates) alert("There were duplicates.");

How copy value from one textbox to another in jQuery?

All one need to do is to bind keyup event on textbox and then copy textbox value to another textbox. Below jQuery code will copy text from txtFirst and copy it to txtSecond. $(document). ready(function() { $('#txtFirst').


1 Answers

You need to use the val() function to get the textbox value. text does not exist as a property only as a function and even then its not the correct function to use in this situation.

var from = $("input#fromAddress").val()

val() is the standard function for getting the value of an input.

like image 66
Darko Z Avatar answered Oct 26 '22 11:10

Darko Z