Solved

JavaScript - get value of input field

Posted on 2014-11-10
4
209 Views
Last Modified: 2014-11-10
HI,
just wondering if there is a simple way to get the value of my tracking_number input field to pass to another input button?

Thanks

<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35">

<input type="button" onClick="if(confirm('This will send an email to the customer with their Delivery Tracking Number.')){location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=?????'}" value="Send Tracking Details">

</div>

Open in new window

0
Comment
Question by:sabecs
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40434238
<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
   <input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35" />
   <input type="button" onclick="doSomething();" value="Send Tracking Details" />
</div>
<script>
    var doSomething = function() {
        var answer = confirm('This will send an email to the customer with their Delivery Tracking Number.');
        if(answer==true) {
             var tn_value = document.getElementById("tracking_number").value;
             location.href = 'view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=' + tn_value;
        }
    }
</script>

Open in new window

0
 
LVL 7

Expert Comment

by:cstsang
ID: 40434243
Try the following:
<script language=javascript>
function check()
{
    var field=document.getElementById("tracking_number");
    if(confirm('This will send an email to the customer with their Delivery Tracking Number.'))
    {
        location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number='+field.value; 
    }
}
</script>
<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35">

<input type="button" onclick="check()" value="Send Tracking Details">

Open in new window

0
 
LVL 8

Expert Comment

by:Mukesh Yadav
ID: 40434289
You just need to replace ?????' with '+ document.getElementById('tracking_number').value

Remaining you have already done.
0
 
LVL 5

Expert Comment

by:Ronak Patel
ID: 40434319
basically its the same as above solutions.. I've just added a validation block.. which will check the tracking number value.. If you have a specific format of your tracking number.. you can validate it by performing RegEx validation..

<script type="text/javascript">

function SendTrackingDetails(obj)
{
	if(confirm('This will send an email to the customer with their Delivery Tracking Number.'))
	{
		if(obj.value != undefined && obj.value != "") //Check if Tracking Number is entered or not..
		{
			location.href='view_upd_order.php?order_id=123&send_tracking=Y&tracking_number=' + obj.value;
		}
		else
		{
			alert('Enter Tracking Number.');
			return false;
		}
	}
}

</script>

<div class="order_details_head">Delivery Tracking Number</div>
<div class="order_details">
<input name="tracking_number"style="width:120px"  type="text" id="tracking_number" value="" size="35" />

<input type="button" onClick="return SendTrackingDetails(document.getElementById('tracking_number'));" value="Send Tracking Details" />

</div>

Open in new window

0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ajax jquery 3 25
jQuery Toggle & Anchor Links 5 43
Responsive Font Size 6 30
Why is initMap returning "not a function" error. 3 32
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question