/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] String to INT

Hi all,

I have a script which uses the result of a PHP query.

[CODE]
function update(dual_start_pin, dual_end_pin)
{
dual_end_pin.value = dual_start_pin.value + “<?php echo $_SESSION[‘order2’];?>” ;

}
[/CODE]

This is what I am rtying to do:

If the var “dual_start_pin” = 1338000 I want the var “dual_end_pin” value to be updated with the value of the $_SESSION var.

At the moment if the “dual_start_pin” = 1338000″ and the $_SESSION var = 10, the output is “133800010”

What am I doing wrong.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@toenailsinJun 15.2008 — the numbers will only be added if they're both integers. you have speech-marks around the php variable meaning its a string. remove them and it should work. if your afraid of a string getting outputted then use:

<?php echo [b](int)[/b]$_SESSION['order2'];?>
Copy linkTweet thisAlerts:
@dcjonesauthorJun 15.2008 — Hi toenailsin

Many thanks for your reply.

I now have:
[CODE]
function update(dual_start_pin, dual_end_pin)
{

dual_end_pin.value = dual_start_pin.value + <?php echo (int)$_SESSION['order2'];?> ;

}
[CODE]

On the form, if I enter "1" into the "dual_start_pin" field, on change the "dual_end_pin" filed updates but still the output is "110"

Any ideas.

Dereck
Copy linkTweet thisAlerts:
@toenailsinJun 15.2008 — oh i didn't notice its an input field value...

use: Number(dual_start_pin.value)
Copy linkTweet thisAlerts:
@dcjonesauthorJun 15.2008 — Hi.

I now have:
[CODE]
function update(dual_start_pin, dual_end_pin)
{

Number(dual_start_pin.value) = Number(dual_start_pin.value) + <?php echo (int)$_SESSION['order2'];?> ;

}
[/CODE]


but I get the error:

"Cannot assign a function result".

Sorry to be a pain.

Many thanks again.

Dereck
Copy linkTweet thisAlerts:
@Declan1991Jun 15.2008 — <i>
</i>dual_start_pin.value = Number(dual_start_pin.value) + &lt;?php echo (int)$_SESSION['order2'];?&gt; ;
Copy linkTweet thisAlerts:
@dcjonesauthorJun 15.2008 — Hi all,

And thanks for your help, fixed.

I do have one more request for help. I have a function that should check if the user has supply one of three options. The function I am using is:
[CODE]
if (document.getElementById('mobile').value.length == "" || document.getElementById('telephone_no').value.length == "" || document.getElementById('email').value.length == "")
alert("You must supply a contact method.");
return false;
[/CODE]


When I run the script the form will not submitt until each of the fields contains user input. What I want is anyone of the three fields.

And you help please.
Copy linkTweet thisAlerts:
@Declan1991Jun 15.2008 — if (document.getElementById('mobile').value.length == "" || document.getElementById('telephone_no').value.length == "" || document.getElementById('email').value.length == "") [color=red]{[/color]
alert("You must supply a contact method.");
return false;
[color=red]}[/color]
Copy linkTweet thisAlerts:
@dcjonesauthorJun 15.2008 — Hi declan.

Sorry to be a pain again but I still can't get this to work correctly. This is what I have:
[CODE]
function validate(){

if (document.getElementById('name_f').value.length < 1) {
alert("Please enter your first name.");
return false;
}
if (document.getElementById('name_l').value.length < 1) {
alert("Please enter your last name.");
return false;
}
if (document.getElementById('secure_id_1').value.length < 1) {
alert("Please enter the security number.");
return false;
}

if (document.getElementById('mobile').value.length == "" || document.getElementById('telephone_no').value.length == "" || document.getElementById('email').value.length == "")
alert("You must supply a contact method.");
return false;
}
return true;
}
[/CODE]


The form will not submit until all 3 elements, "mobile","telephone_no" and "email" fields have user input in them.

Can you this anything wrong.
Copy linkTweet thisAlerts:
@Declan1991Jun 15.2008 — Sorry, I didn't understand you the first time. You said "OR" so that means that it returns false if any of them are blank.if (document.getElementById('mobile').value.length == "" &amp;&amp; document.getElementById('telephone_no').value.length == "" &amp;&amp; document.getElementById('email').value.length == "")
alert("You must supply a contact method.");
return false;
}
That is if all of them are blank, it returns false.
Copy linkTweet thisAlerts:
@dcjonesauthorJun 15.2008 — Hi declan.

Thank you for your help.

All working correctly..
×

Success!

Help @dcjones 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...