Xanco Posted April 6, 2013 Share Posted April 6, 2013 Hello peoples. Right, here's what I'm trying to do; the user fills out a form (that inserts a link in HTML for them), in this form there are to variables ($address and $webname). These are then saved, then are combined with javascript to produce the following in a text area: <a href=$address>$webname</a> but instead I get this: <a href=></a> Here's my php code stating the variables: $address = empty ($_GET["address"]) ? "" : $_GET["address"]; $webname = empty ($_GET["webname"]) ? "" : $_GET["webname"]; Here's my form: <form id="webaddressenter" style="display:none;"> <label for="address">Your URL:</label> <input type="text" name="address" value="<?php echo $address; ?>" placeholder="http:www.google.com"><br /> <label for="webname">Website name:</label> <input type="text" name="webname" value="<?php echo $webname; ?>" placeholder="Google"><br /> <input type="button" value="submit" onclick="insertaddress()" id="tag"> </form> Here's my javascript function function insertaddress(){ insert(window.lstText,'<a href=<?php echo $address ?>><?php echo $webname ?></a>') } Quote Link to comment https://forums.phpfreaks.com/topic/276611-php-variables-not-passing-through-javascript-function/ Share on other sites More sharing options...
trq Posted April 6, 2013 Share Posted April 6, 2013 The variables to not exist until after the form has been submitted. Quote Link to comment https://forums.phpfreaks.com/topic/276611-php-variables-not-passing-through-javascript-function/#findComment-1423271 Share on other sites More sharing options...
Xanco Posted April 6, 2013 Author Share Posted April 6, 2013 Thanks, I'll try something else Quote Link to comment https://forums.phpfreaks.com/topic/276611-php-variables-not-passing-through-javascript-function/#findComment-1423273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.