Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:41:12+00:00 2026-06-02T02:41:12+00:00

Well Javascript is new to me but I didn’t think it would cause a

  • 0

Well Javascript is new to me but I didn’t think it would cause a problem like this. Either I’m doing this wrong or I should be using cookies instead.

I’m trying to use javascript to submit POST data to a php page via a link. I asked a question earlier about how to pass data like this, and besides AJAX it basically came down to making a hidden form and having javascript submit it. I don’t know anything about AJAX or Jquery right now so I’m sticking with the form method.

BUT for some reason the code wasn’t posting my data. I couldn’t figure out why until I accidentally clicked it twice in a row, and then the data showed up.

The scenario is the link takes you to the page where the data goes, and the data gets processed and shown via var_dump.

Here’s necessary coding.

function red()
{
    alert('This is happening');
    document.traf.traf2.value = 3;
    document.traf.submit(); 
}

and

echo "<form name='traf' method='post' action='newphpwriterthing.php'><input type='hidden' name='traf2' /></form>"; //FORM SET
echo "<a href='newphpwriterthing.php' onClick='red()'> <img src='red.png' height='150' /></a>";

The function seems to be called fine, but I was under the impression that the value and submitting wasn’t doing anything…until I hit it twice on accident and it did exactly what it should.

I also tried clicking once to get to the page, and then refreshing multiple times to see if the value just “wasn’t there yet”. Nothing.

What’s going on here and how do I fix it?? Am I better off using cookies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:41:15+00:00Added an answer on June 2, 2026 at 2:41 am

    You link have a href so it’s just getting you to that URL.

    Add return false; to the end of your red function.

    Or maybe you should chage onClick='red()' to onClick='red() return false;' – didn’t used it that way for some time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well im new to javascript but why does this not work, all i want
I've been doing a little JavaScript (well, more like jQuery) for a while now
I'm quite new with javascript and I don't understand this problem: $(function() { var
i'm pretty new to this jquery/javascript stuff but i have this jsfiddle example .
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
Well, I'm completely new to JavaScript. Can you please tell me what type of
I know what AJAX stands for. I know javascript passably well. But frankly I'm
I have a JavaScript snippet that runs very well on Firefox and Safari, but
I am relatively new to Javascript so I'm hoping this is a simple mistake.
I've been programming for a few years but I'm new to JavaScript. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.