Solved

JavaScript - get value of input field

Posted on 2014-11-10
4
202 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 6

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now