Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert javascript into input field

Status
Not open for further replies.
This will insert the string into the 'Email' field. You should be able to work out how to do the other one:

Code:
document.getElementById('Email').value = '<script language="JavaScript" type="text/javascript" src="[URL unfurl="true"]http://www.ABC.com/members/display.php?token=email"></script>';[/URL]

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Call me dumb today but is this apart of a var function?

What should the rest of the code do?
 
Call me dumb today but is this apart of a var function?

What should the rest of the code do?

I have no idea what you mean by that.

You asked how to "insert this" into a field.

What I got from that basic description is that you wanted to insert the following string as the value of the fields, so I gave you code to insert the string (which just so happened to look like code) as the value of the 'Email' input field.

If that is not what you want, perhaps you can help us to help you by explaining in a bit more detail than "insert this".

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
What is it that you actually want to do?

Do you want to set the value of an input field to an arbitrary string? If so (and I'll use a string that doesn't look like code so as not to confuse the issue), then this WILL work:

Code:
document.getElementById('Email').value = 'abcdefg';

That code does NOT go inside the input field. It is JavaScript code that can be placed anywhere that JavaScript code would normally be placed (i.e. inside a <script> block).

If you do not want to set the value of an input field to an arbitrary string, then, as I've already asked, can you give a better description of what it is you want to achieve.

Right now I get the impression you are just trying random things without even understanding what it is you are trying.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Sorry about that. What I want to do is have the javascript string (which displays the affiliate email address) be inserted into and input field so that when a form is filled out he gets credit for the sale:

This javascript displays the affiliate email address:
<script language="JavaScript" type="text/javascript" src="
So in other words have the above javascript string be inserted into an input value so it gets emailed to me:

<input id="Email" name="Email" type="text" size="30" /><input name="emailagent" type="HIDDEN" class="textfield" id="emailagent" value='PUT JAVASCRIPT HERE' />

Does this make sense?
 
This javascript displays the affiliate email address:

So in other words have the above javascript string be inserted into an input value so it gets emailed to me:

Your first point implies that the script linked to by the <script> element outputs an email address, and it this address you wish to insert. For this, we would need to see the script (which you, for whatever reason, do not want to give us the real URL to) to know what it is doing.

Your second point states simply that you want the above string (which looks like code) inserted as the value.

The two are very, very different requests.

I will assume for one moment that you want the former (something new) rather than the latter (which you have been asking for all along). This being the case, we would need to see the code in question before we can help.

If I have it wrong and it is actually the latter you desire, then my very first post will achieve the result you seek.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Here is the code you were asking about:

<?PHP
#############################################################
## iDevAffiliate Version 5.2
## Copyright - iDevDirect.com L.L.C.
## Website: ## Support: ## Email: support@idevdirect.com
#############################################################

/*
--------------------------------------------------------------
You can alter the CSS below but do not remove the Java Script
Tags. They are required because this file is being called
via Java Script.

Any invalid coding adjustments to this page will result in
Java Script errors in the page you've placed the Java Script
code snippet. Adjustments to this file are not supported by
iDevDirect. We highly suggest making a backup of the
original display.php file before making changes.

If you're wondering what the variable $idev represents, that
is the affiliate ID number and is obtained from the
/includes/tracking.php file.
--------------------------------------------------------------
*/

$token_tag_id = "";
$token_tag_username = "";
$token_tag_phone = "";
$token_tag_name = "";
$token_tag_company = "";
$token_tag_city = "";
$token_tag_state = "";
$token_tag_email = "";
$token_tag_website = "";

?>


<?PHP

$time_now = time();
include ("API/config.php");
include ("includes/validation_functions.php");
include ("includes/tracking.php");

// SANITIZE AND SET INCOMING TOKEN VARIABLE
// -----------------------------------------------------------
$token = check_type('token');

if ($idev) {
// GET AFFILIATE DATA
// -----------------------------------------------------------
$aff_data = mysql_query("select username, phone, f_name, l_name, company, city, state, email, url from idevaff_affiliates where id = '$idev'");
if (mysql_num_rows($aff_data)) {
$aff_data = mysql_fetch_array($aff_data);
$affiliate_username = $aff_data['username'];
$affiliate_phone = $aff_data['phone'];
$affiliate_fname = $aff_data['f_name'];
$affiliate_lname = $aff_data['l_name'];
$affiliate_name = $affiliate_fname . "&nbsp;" . $affiliate_lname;
$affiliate_company = $aff_data['company'];
$affiliate_city = $aff_data['city'];
$affiliate_state = $aff_data['state'];
$affiliate_email = $aff_data['email'];
$affiliate_website = $aff_data['url'];
} }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE ID
// -----------------------------------------------------------
if (($token == 'id') || (!$token)) {
if ($idev)
// -----------------------------------------------------------
{ $token_id = $idev;
} else { $token_id = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_id $token_id</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE USERNAME
// -----------------------------------------------------------
if ($token == 'username') {
if ($idev)
// -----------------------------------------------------------
{ $token_username = $affiliate_username;
} else { $token_username = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_username $token_username</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE PHONE
// -----------------------------------------------------------
if ($token == 'phone') {
if (($idev) && ($affiliate_phone))
// -----------------------------------------------------------
{ $token_phone = $affiliate_phone;
} else { $token_phone = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_phone $token_phone</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE NAME
// -----------------------------------------------------------
if ($token == 'name') {
if (($idev) && ($affiliate_name))
// -----------------------------------------------------------
{ $token_name = $affiliate_name;
} else { $token_name = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_name $token_name</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE COMPANY
// -----------------------------------------------------------
if ($token == 'company') {
if (($idev) && ($affiliate_company))
// -----------------------------------------------------------
{ $token_company = $affiliate_company;
} else { $token_company = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_company $token_company</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE CITY
// -----------------------------------------------------------
if ($token == 'city') {
if (($idev) && ($affiliate_city))
// -----------------------------------------------------------
{ $token_city = $affiliate_city;
} else { $token_city = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_city $token_city</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE STATE
// -----------------------------------------------------------
if ($token == 'state') {
if (($idev) && ($affiliate_state))
// -----------------------------------------------------------
{ $token_state = $affiliate_state;
} else { $token_state = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_state $token_state</p>\");"; }

// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE email
// -----------------------------------------------------------
if ($token == 'email') {
if (($idev) && ($affiliate_email))
// -----------------------------------------------------------
{ $token_email = $affiliate_email;
} else { $token_tag_email = "yyyyy"; }
// -----------------------------------------------------------
print "$token_tag_email $token_email"; }
// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE WEBSITE
// -----------------------------------------------------------
if ($token == 'website') {
if (($idev) && ($affiliate_website) && ($affiliate_website != "// -----------------------------------------------------------
{ $token_website = "<a href=\'$affiliate_website\' target=\'_blank\'>$affiliate_website</a>";
} else { $token_website = "N/A"; }
// -----------------------------------------------------------
print "document.write(\"<p class='idev'>$token_tag_website $token_website</p>\");"; }


$affiliate_logo = "$logo_default";
// -----------------------------------------------------------
// DISPLAY TOKEN : AFFILIATE LOGO
// -----------------------------------------------------------
if ($token == 'logo') {
// -----------------------------------------------------------
// GET LOGO/IMAGE DATA
// -----------------------------------------------------------
if (isset($idev)) {
$logo_data = mysql_query("select filename from idevaff_logos where id = '$idev' and approved = '1'");
if (mysql_num_rows($logo_data)) {
$logo_data = mysql_fetch_array($logo_data);
$affiliate_logo = $logo_data['filename'];

$logo_location = $base_url . "/logos/" . $affiliate_logo; } else {
$logo_location = $logo_default; }
}
// -----------------------------------------------------------
list($width, $height, $type, $attr) = getimagesize("$logo_location");
// -----------------------------------------------------------
print "document.write(\"<img border='0' src='$logo_location' width='$width' height='$height'>\");";

}

?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top