/    Sign up×
Community /Pin to ProfileBookmark

Form capture problems !

Form captured problems !

Hi All

The title doesn’t best describe my problem but I can’t think of a better way so I’ll just explain.

I have a simplified version of what I’m working with here.

[url]http://www.ttmt.org.uk/forum/[/url]

It’s a font tester where you can select text and font size from the drop menus and it will be set below in a given font. The values are captured with jQuery and the image is produced with the PHP GD library but thats all working.

My problem is I want to use the input text area and the text drop down menu to set the text that is used.

If text is typed into the text area I would like that to used. If text is selected from the drop down I would like that to be used.

Hope this makes sense and someone can help. Any help would be greatly appreciated.

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>
<meta name=”robots” content=”noindex, nofollow” />

<title></title>
<style type=”text/css” media=”screen”>
*{margin:0;padding:0;}
#content{margin:20px;}
form{margin:0 0 20px 0;}
#inputText{width:300px;}
</style>

</head>

<body>

<div id=”content”>

<form method=”” action=”” id=”testerForm”>

<input id=”inputText” type=”text” name=”text” value=”” />

<select name=”text” id=”selectText”>
<option value=””>Text</option>
<option rendertype=”o”>0123456789</option>
<option rendertype=”o”>The quick brown fox jumps over the lazy dog</option>
<option rendertype=”o”>Fjord Nymphs XV beg quick waltz</option>
<option rendertype=”o”>J.Q. Vandz struck my big fox whelp</option>
</select>

<select name=”size” id=”selectSize”>
<option value=””>Size</option>
<option value=”40″>40</option>
<option value=”60″>60</option>
<option value=”84″>84</option>
<option value=”108″>108</option>
</select>

<input type=”submit” name=”submit” id=”set” value=”Set” />

</form>

<div class=”fontTester”>

</div>

</div><!– #content –>

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script>

<script type=”text/javascript” charset=”utf-8″>

var text = ‘Test’;
var size = 70;
var font = ‘corbelb.ttf’;
var dataString = ‘text=’ + text + ‘&size=’ + size + ‘&font=’ + font;
$(“.fontTester”).html(“<img src=’sample.php?” + dataString + “‘ />”);

//
$(‘#set’).click(function(e){
e.preventDefault();
//

if($(‘#inputText’).val() != ”){
text = $(‘#inputText’).val();
}

if($(‘#selectText’).val() != ” ){
text = $(‘#selectText’).val();
$(‘#inputText’).val(”);
}

if($(‘#selectSize’).val() != ”){
size = $(‘#selectSize’).val();
}

dataString = ‘text=’ + text + ‘&size=’ + size + ‘&font=’ + font;
$(“.fontTester”).find(“img”).remove();
$(“.fontTester”).html(“<img src=’sample.php?” + dataString + “‘ />”);

});

</script>
</body>
</html>

[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@3NexJan 11.2012 — See if this works for you. If you're unsure why i changed some stuff the way i did, ask away. I'll leave you to try to figure it out yourself first. Of course, there is still the possibility that you won't even like my changes, but at least you'll find the answer to your question in here. Like for example the fact that I removed the Set button entirely will now put a lot of weight onto your sample.php file, so see if that will pose a problem.

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="robots" content="noindex, nofollow" />

<title></title>
<style type="text/css" media="screen">
*{margin:0;padding:0;}
#content{margin:20px;}
form{margin:0 0 20px 0;}
#inputText{width:300px;}
</style>

</head>

<body>

<div id="content">

<form method="" action="" id="testerForm">

<input onkeyup="updateText(this.value);" id="inputText" type="text" name="text" value="" />

<select name="text" id="selectText" onchange="updateText(this.value);">
<option>Text</option>
<option rendertype="o">0123456789</option>
<option rendertype="o">The quick brown fox jumps over the lazy dog</option>
<option rendertype="o">Fjord Nymphs XV beg quick waltz</option>
<option rendertype="o">J.Q. Vandz struck my big fox whelp</option>
</select>

<select name="size" id="selectSize" onchange="updateText();">
<option value="">Size</option>
<option value="40">40</option>
<option value="60">60</option>
<option value="84">84</option>
<option value="108">108</option>
</select>

</form>

<div class="fontTester">

</div>

</div><!-- #content -->



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

<script type="text/javascript" charset="utf-8">

var text = 'Test';
var size = 70;
var font = 'corbelb.ttf';
var dataString = 'text=' + text + '&size=' + size + '&font=' + font;

function updateText(input) {

if((input)) {
text = input;
}

if($('#selectSize').val() != ''){
size = $('#selectSize').val();
}

dataString = 'text=' + text + '&size=' + size + '&font=' + font;
$(".fontTester").find("img").remove();
$(".fontTester").html("<img src='http://www.ttmt.org.uk/forum/sample.php?" + dataString + "' />");

}

</script>

</body>
</html>

[/CODE]
Copy linkTweet thisAlerts:
@ttmtauthorJan 12.2012 — Thanks 3Nex thats working for me now.
×

Success!

Help @ttmt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...