Solved

JavaScript - get value of input field

Posted on 2014-11-10
4
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 9

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery Ajax - on change event not being picked up 9 57
JS to redirect to prev page 8 42
Set css in function 11 51
Form submit takes only for one form 23 45
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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…
The viewer will learn how to dynamically set the form action using jQuery.
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…

739 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