robot javascript HELP! 
May 10th, 2006, 09:05 AM
| | | robot javascript HELP!
Hi,
I need to make a robot that fills forms. I already made that with php
sites, but now I need that in a javascript pages site ( the robot can
be php,asp, asp.net ), anyone knows how can I do it? or somewhere I can
find more info?
Thanks!
Marcelo | 
May 10th, 2006, 10:15 AM
| | | Re: robot javascript HELP!
Marcelo wrote:
[color=blue]
> Hi,
>
> I need to make a robot that fills forms. I already made that with php
> sites, but now I need that in a javascript pages site ( the robot can
> be php,asp, asp.net ), anyone knows how can I do it? or somewhere I can
> find more info?
>
> Thanks!
>
> Marcelo[/color]
Hi,
Do you want a JS script that fills in a form?
JS must be on the same page as the form, or you might hit into
security-issues.
(If you want to fill a form on another window.)
If it is on the same page, just fill in what you want like this:
<form action="bal.php" name="myForm">
firstname: <input type="text" name="firstname" value="">
<br>
lastname: <input type="text" name="lastname" value="">
<br>
<input type="submit" value="send">
</form>
<script type="text/javascript">
// fill it
document.forms["myForm"].firstname.value = "Zaphod";
document.forms["myForm"].lastname.value = "Beeblebrox";
// send it
document.forms["myForm"].submit();
</script>
Is that what you are looking for?
Regards,
Erwin Moller | 
May 10th, 2006, 01:05 PM
| | | Re: robot javascript HELP!
Hi,
Thanks for the answer.
I want that php fills a javascript form, but I don't know how to send
the values or select the values of combo boxes ( in some cases ).
Best Regards
Marcelo | 
May 10th, 2006, 02:45 PM
| | | Re: robot javascript HELP!
Marcelo a écrit :[color=blue]
>
> I want that php fills a javascript form, but I don't know how to send
> the values or select the values of combo boxes ( in some cases ).[/color]
Usually a form is written and works in html.
Scripts in JS are only to help in filling fields by users(*)
Scripts in php can pre-fill fields or/and display necessary options of
selects
Php knows how to receive fields or combo boxes values,
there is nothing to do in JavaScript to send those.
On re-issue of form from php, the php fills fields it knows.
(*) JS looks if fields are filled up and, if not, prevent submit
<form onsubmit="return validate(this)" blah ...>
function validate(aForm) {
for (var i=0;i<aForm.length;i++) {
if(aform[i].type == 'text' && aForm[i].value == '') {
alert(txt+aForm[i].name);
aForm[i].focus();
aForm[i].select();
return false;
}
if(aform[i].type == 'select' && aForm[i].value == '') {
alert('Please choice in list : '+aForm[i].name);
aForm[i].focus();
aForm[i].select();
return false;
}
if(aform[i].type == 'radio') {
var e = aForm.elements[aForm[i].name];
if(e.length>0) {
var ok = true;
for(var j=0;j<e.length;j++) if(e.[j].checked) ok=false;
if(ok) {
alert('Please choice : '+aForm[i].name);
aForm[i][0].focus();
return false;
}
}
}
}
return true;
}
--
Stephane Moriaux et son [moins] vieux Mac | 
May 11th, 2006, 07:55 AM
| | | Re: robot javascript HELP!
Thanks for the info, so It can't be do it? ( with php or asp ala
"robot form filler" ), can be do it with a win 32 app?
Basically I need something that hide some fields of a webpage and show
partially in other site.
field1 field2 field3
â–¼
page1(form in javascript)
â–¼
site1
â–¼
site2 ("masked site")
â–¼
page1
â–¼
field1 field2
â–¼
USER ( only see 2 fields )
Thanks
MARCELO | 
May 11th, 2006, 09:25 AM
| | | Re: robot javascript HELP!
Marcelo wrote:
[color=blue]
> Hi,
>
> Thanks for the answer.
>
> I want that php fills a javascript form, but I don't know how to send
> the values or select the values of combo boxes ( in some cases ).
>
> Best Regards
>
> Marcelo[/color]
Hi Marcelo,
I think you are confusing two things: serverside and clientside.
1) PHP runs only at server, and produces HTML and the Javascript.
2) The delivered HTML (including JS) is executed in a client (=browser).
So you cannot directly let PHP fill a form.
Of course, you are free to let PHP fill in values for formelements, and let
PHP SELECT some options in a SELECT or in a RADIO typed formelement, but
remember that this must happen at 'producetime', that is when you make the
HTML.
Once PHP has delivered the HTML, it is completely out of touch with the HTML
page.
So when you write: "I want that php fills a javascript form", do you mean
you KNOW what values you want in the form?
Please rephrase your question (or rethink your design).
If you want to let your form on the client communicate with some PHP scripts
on some server, solutions exists (AJAX comes into mind), but I am unsure
what you want.
Good luck!
Regards,
Erwin Moller | 
May 11th, 2006, 09:45 AM
| | | Re: robot javascript HELP!
Hi Erwin,
I need a roobot that fills a form, I already made that with php (
sending the url with values ) but i want to make the same thing on a
javascript page, so I don't know how to send the values
[color=blue]
>So when you write: "I want that php fills a javascript form", do you mean
>you KNOW what values you want in the form?[/color]
Yes I know
Thanks
Regards
Marcelo | 
May 11th, 2006, 11:15 AM
| | | Re: robot javascript HELP!
Marcelo a écrit :[color=blue]
> Thanks for the info, so It can't be do it? ( with php or asp ala
> "robot form filler" ), can be do it with a win 32 app?
> Basically I need something that hide some fields of a webpage and show
> partially in other site.
>
>
> field1 field2 field3
> â–¼
> page1(form in javascript)[/color]
it is what I don't understand : why a form in JS if you use php ?
[color=blue]
> â–¼
> site1
> â–¼
> site2 ("masked site")
> â–¼
> page1
> â–¼
> field1 field2
> â–¼
> USER ( only see 2 fields )
>
>
> Thanks
>
> MARCELO[/color]
[ = PHP = ] _______________
To non display a fild already filled up :
(it will be write in html code and will be submit with others fields in
same form)
<input type="text" name="field1"
<? if(isSet $field1) echo "style=\"display:none\""; ?>
value="<? echo $field1 ?>" >
or to do not write it if previously filled up
<? if(!isSet $field1) { ?>
<input type="text" name="field1">
<? } ?>
same with a combo box
<select name="combo1">
<? if($combo1 != 'apple')
echo "<option value=\"apple\">Apple</option>\n";
?>
[ = JS = ] ______________________
(not a good idea) (suppose you are in php)
Will virtally only write empty fields
<?
/* php to set/get php _POST variables */
?>
<html>
<script type="text/javascript">
var fld = new Array();
fld[1] = '<? echo $field1 ?>';
fld[2] = '<? echo $field2 ?>';
function setFields() {
var txt = '';
var ok = false;
for(var i=0;i<fld.length;i++)
if(fld[i] != '') {
txt += '<input type="text" name="field'+(+1+i)+'">
ok = true;
}
if(ok) txt += '<input type="submit" value="pronto">';
document.write(txt);
}
</script>
<form name="form1" action="myPhp.php" method="post">
<script type="text/javascript">
setFields();
</script>
</form>
</html>
--
Stephane Moriaux et son [moins] vieux Mac | 
May 11th, 2006, 11:15 AM
| | | Re: robot javascript HELP!
Marcelo a écrit :[color=blue]
> Thanks for the info, so It can't be do it? ( with php or asp ala
> "robot form filler" ), can be do it with a win 32 app?
> Basically I need something that hide some fields of a webpage and show
> partially in other site.
>
>
> field1 field2 field3
> â–¼
> page1(form in javascript)[/color]
it is what I don't understand : why a form in JS if you use php ?
[color=blue]
> â–¼
> site1
> â–¼
> site2 ("masked site")
> â–¼
> page1
> â–¼
> field1 field2
> â–¼
> USER ( only see 2 fields )
>
>
> Thanks
>
> MARCELO[/color]
[ = PHP = ] _______________
To non display a fild already filled up :
(it will be write in html code and will be submit with others fields in
same form)
<input type="text" name="field1"
<? if(isSet $field1) echo "style=\"display:none\""; ?>
value="<? echo $field1 ?>" >
or to do not write it if previously filled up
<? if(!isSet $field1) { ?>
<input type="text" name="field1">
<? } ?>
same with a combo box
<select name="combo1">
<? if($combo1 != 'apple')
echo "<option value=\"apple\">Apple</option>\n";
?>
[ = JS = ] ______________________
(not a good idea) (suppose you are in php)
Will virtally only write empty fields
<?
/* php to set/get php _POST variables */
?>
<html>
<script type="text/javascript">
var fld = new Array();
fld[1] = '<? echo $field1 ?>';
fld[2] = '<? echo $field2 ?>';
function setFields() {
var txt = '';
var ok = false;
for(var i=0;i<fld.length;i++)
if(fld[i] != '') {
txt += '<input type="text" name="field'+(+1+i)+'">
ok = true;
}
if(ok) txt += '<input type="submit" value="pronto">';
document.write(txt);
}
</script>
<form name="form1" action="myPhp.php" method="post">
<script type="text/javascript">
setFields();
</script>
</form>
</html>
--
Stephane Moriaux et son [moins] vieux Mac | 
May 11th, 2006, 12:05 PM
| | | Re: robot javascript HELP!
Marcelo a écrit :[color=blue]
> Hi Erwin,
>
> I need a roobot that fills a form, I already made that with php (
> sending the url with values ) but i want to make the same thing on a
> javascript page, so I don't know how to send the values
>
>[color=green]
>>So when you write: "I want that php fills a javascript form", do you mean
>>you KNOW what values you want in the form?[/color]
>
>
> Yes I know[/color]
to non visually display fields by javascript :
<?
/* php to set/get php _POST variables */
?>
<html>
<script type="text/javascript">
var fld = new Array();
fld[1] = '<? echo $field1 ?>';
fld[2] = '<? echo $field2 ?>';
function hideFields() {
var f = document.forms['form1'];
var j = 0;
for(var i=0;i<f.length;i++)
if(f[i].type == 'text') {
if(fld[j] != '')
f[i].style.display = 'none';
j++;
}
}
onload = hideFields;
function showHideField(fieldName,what) {
var f = document.forms['form1'].elements[fieldName];
if(f.style.display != 'none') {
f.style.display = 'none';
what.value = 'Show '+fieldName;
}
else {
f.style.display = 'inline';
what.value = 'Hide '+fieldName;
}
}
</script>
<form name="form1" action="myPhp.php" method="post">
<p>Field 1 : <input type="text" name="field1"
value="<? echo $field1 ?>">
</p>
<p>Field 2 : <input type="text" name="field2"
value="<? echo $field2 ?>">
</p>
<p><input type="submit" value="Send">
</p>
<p><input type="button" value="Show/Hide Field 1"
onclick="showHideField('field1',this);">
<input type="button" value="Show/Hide Field 2"
onclick="showHideField('field2',this);">
</p>
</form>
</html>
--
Stephane Moriaux et son [moins] vieux Mac | 
May 11th, 2006, 12:15 PM
| | | Re: robot javascript HELP!
ASM a écrit :[color=blue]
>[/color]
[some code]
correction :
<html>
<script type="text/javascript">
var fld = new Array();
fld[1] = '<? echo $field1 ?>';
fld[2] = '<? echo $field2 ?>';
function setFields() {
var txt = '';
var ok = false;
for(var i=0;i<fld.length;i++)
if(fld[i] == '') {
txt += '<input type="text" name="field'+(+1+i)+'">';
ok = true;
}
if(ok) txt += '<input type="submit" value="pronto">';
document.write(txt);
}
</script>
<form name="form1" action="myPhp.php" method="post">
<script type="text/javascript">
setFields();
</script>
</form>
</html>
--
Stephane Moriaux et son [moins] vieux Mac | 
May 13th, 2006, 02:35 AM
| | | Re: robot javascript HELP!
[color=blue][color=green]
>> field1 field2 field3
>> â–¼
>> page1(form in javascript)[/color][/color]
[color=blue]
>it is what I don't understand : why a form in JS if you use php ?[/color]
Because the "site1" have javascript pages, and I don't have control
over it.
Here's a little explanation why I need that.
We have a company that sells some products,our company represents an
international ( BIG ) one, we have the rights to sell on my country,
our customers buy the products trough a website that is hosted by the
international company. Our marketing departament decided to sell some
products at different prices that the big company does, so we need to
mask that info with our prices ( the international company can't do it
at this moment ), thats why i need to "mask" the international site.
Marcelo | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|