...

View Full Version : A New Challenge~only for pros though :)



imiscor
05-27-2004, 05:32 PM
I want to make a script~~~

I want this script to do the following~~

I have no clue how to do this ~~~~

: The Script will be used with a form. If the user is entering text into the form and reaches a limit, say X charcters(300 for example) , the test then automatically goes into a different form box.

Example:

I have a Form item called Description:
Someone writes 300 characters in Description and the second they hit 301st charcter, that character appears in item Description2 and keeps going. Any idea? Anyone brave enough to handle that?

Vladdy
05-27-2004, 05:50 PM
I though it was supposed to be challenging :rolleyes:


<textarea onkeyup="if(this.value.length>300) this.nextSibling.focus();"></textarea><textarea></textarea>
Try again :cool: :D :D

imiscor
05-27-2004, 05:55 PM
No Idea how I would make those functions. :( I'm obviously a lesser lifeform than you.

sad69
05-27-2004, 05:55 PM
Okay this is how you'd do it:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>

<script>
function check_length_refocus(txt1, len, txt2) {
if(txt1.value.length == len) {
document.getElementById(txt2).focus();
}
}
</script>

</head>
<body>
<form>
<textarea id="descr_1" onkeypress="check_length_refocus(this, 5, 'descr_2');"></textarea>
<textarea id="descr_2" onkeypress=""></textarea>
</form>
</body>
</html>


If you have troubles applying this to your code, let me know and I'll help adapt it..

But I think you should stop asking questions in this way: "I've got a challenge for you!!" Like what's up with that man? You want us to do the work for you or what? Throw some paper this way then..

Google and the search feature on this website are excellent resources. You should research what you're trying to accomplish first, try it, and then if you run into problems you can post them here and we can help you debug them.

That's just what I think anyway..

Hope that helps,
Sadiq.

imiscor
05-27-2004, 05:57 PM
This is the code I have right now.. Ignore the stuff that you dont understand, its net.data



%{
###########################################################
HTML Call_addnews This is the main section where news is
###########################################################
%}
%DEFINE{
c1="500"
c2="500"
%}
%HTML(Call_addnews) {
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<meta http-equiv="Content-type" content="text/html; charset=US-ASCII" />
<link rel="stylesheet" href="master_style.css" type="text/css">
<script type="text/javascript">
function gettSelection(ta)
{ var bits = [ta.value,'','',''];
if(document.selection)
{ var vs = '#$%^%$#';
var tr=document.selection.createRange()
if(tr.parentElement()!=ta) return null;
bits[2] = tr.text;
tr.text = vs;
fb = ta.value.split(vs);
tr.moveStart('character',-vs.length);
tr.text = bits[2];
bits[1] = fb[0];
bits[3] = fb[1];
}
else
{ if(ta.selectionStart == ta.selectionEnd) return null;
bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
}
return bits;
}

function matchPTags(str)
{ str = ' ' + str + ' ';
ot = str.split(/\[[B|U|I].*?\]/i);
ct = str.split(/\[\/[B|U|I].*?\]/i);
return ot.length==ct.length;
}

function addPTag(ta,pTag)
{ bits = gettSelection(ta);
if(bits)
{ if(!matchPTags(bits[2]))
{ alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
return;
}
ta.value = bits[1] + '<' + pTag + '>' + bits[2] + '</' + pTag + '>' + bits[3];
}
}

function addImage(){
var img_location= prompt ("write the name of the file after the last '/' , then copy this all and paste it where you want the image","<IMG SRC=http://67.94.110.170/artis_news/images/")
}


function validate(form) {
if (form.newsTitle.value == "" || form.newsTitle.value == " ")
{
alert("Please enter a Job Title")
return false
}

if (form.posterName.value == "" || form.posterName.value == " ")
{
alert("Please enter a value")
return false
}
return true

if (form.datePosted.value == "" || form.datePosted.value == " ")
{
alert("Please enter a Date")
return false
}
return true

if (form.Description.value == "" || form.Description.value == " ")
{
form.Description.value="NA"
return true
}
return true
}

function checkUser(key) {
if (key == "" || key == " ") {
location.href = "..//signin.d2w/welcome";}
}


</script>
</head>

<body bgcolor="#FFFFFF" bgcolor="#FFFFFF" onLoad="javascript:checkUser($(employeeid))">
<h3><center>Post News</center></h3>
<hr>
<form name="NewJobForm" method="post" onSubmit="return validate(this)" action="Call_inputnewsDatabase">
<div align="center">
<table width="@dtw_radd(c1, c2)" border="3" cellspacing="1" cellpadding="1" bordercolor="002d64">

<tr>
<td width="$(c1)"><b><font size="-1">News Title:</font></b></td>
<td width="$(c2)">
<input type="text" name="newsTitle" value="">
</td>
</tr>

<tr>
<td width="$(c1)"><b><font size="-1">Poster:</font></b></td>
<td width="$(c2)">
<input type="text" name="posterName" value="">
</td>
</tr>



<tr>
<td width="$(c1)"><b><font size="-1">Date Posted:</font></b></td>
<td width="$(c2)">
<input type="text" name="datePosted">
</td>
</tr>

<tr>
<td width="$(c1)"><b><font size="-1">Story:</font></b></td>
<td width="$(c2)">
<textarea rows=5 cols=60 name="Description" wrap = "soft"></textarea>
</td>
</tr>

<tr>
<td width="$(c1)"><b><font size="-1">Display Story?:</font></b></td>
<td>
Yes<input type="radio" name="Display" value="1" checked> No <input type="radio" name="Display" value="0">
</td>
</tr>
</table>

<p><input type="submit" value="Post News">
<input type="reset" value="Reset"><INPUT TYPE="button" VALUE="Image" onClick="addImage()">
<button onclick="addPTag(document.getElementById('Description'),'I')"><i>Italic</i></button>
<button onclick="addPTag(document.getElementById('Description'),'U')"><u>Underline</u></button>
<button onclick="addPTag(document.getElementById('Description'),'B')"><b>Bold</b></button> </p>
<button onclick="addPTag(document.getElementById('Description'),'P')">Paragraph</button>
<button onclick="addPTag(document.getElementById('Description'),'CENTER')">Align Center</button>
<button onclick="addPTag(document.getElementById('Description'),'LEFT')">Align Left</button>
<button onclick="addPTag(document.getElementById('Description'),'RIGHT')">Align Right</button>
</div>
<input type="hidden" value="$(employeeid)" name="employeeid">
<input type="hidden" value="$(user_type)" name="user_type">
</form>
%include "$(includePath)footer.gfe"
</body>
</html>
%}
%{\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/%}

imiscor
05-27-2004, 06:00 PM
I appreciate your help, I guess my question asking method is flawed for 2 reasons. 1. I really DID think these were really hard :) 2. On this other forum where I used to write a lot of C++ someone else would pose questions like that and it kinda grew on me :/

brothercake
05-27-2004, 06:19 PM
It's an easy mistake to make :) Generally, it's best to avoid subject titles which are leading in some way - titles like "here's a challenge for you experts" and so on, they're cheap psychological tactics - trying to play to people's ego and make someone think "oh well, I'll answer this question to show what an expert I am"

That's how it comes across anyway, and that gets people's backs up because it's leading, not an open request for help.

sad69
05-27-2004, 06:28 PM
I appreciate your help, I guess my question asking method is flawed for 2 reasons. 1. I really DID think these were really hard 2. On this other forum where I used to write a lot of C++ someone else would pose questions like that and it kinda grew on me :/


Ok.. well stop it, it's annoying! :p

As for the code you posted, 3 things:
-wrap it in [ code ] [ /code ] tags, no spaces in there..
-make sure your code is formatted and readable
-which textboxes/textareas do you want to apply this 'hit the character limit and refocus' function?

If you want it on all your text inputs and textareas, here ya go:


...
<input type="text" name="newsTitle" value="" id="nTitle" onkeypress="check_length_refocus(this, 20, 'pTitle');">
...
<input type="text" name="posterName" value="" id="pTitle" onkeypress="check_length_refocus(this, 15, 'dTitle');">
...
<input type="text" name="datePosted" id="dTitle" onkeypress="check_length_refocus(this, 10, 'descr');">
...
<textarea rows=5 cols=60 name="Description" wrap = "soft" id="descr" onkeypress="check_length_refocus(this, 300, 'disp');"></textarea>
...
<input type="radio" name="Display" value="1" checked id="disp">
...


If that's not what you want, explain better..

Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum