Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ajax / Javascript Question

Featured Replies

Hi guys having trouble with this one, been trying to figure this one out now for a while so hoping someone can point me in the right direction and any help much appreciated!

 

 

 

The story is...

1) I have an Ajax Div which updates dynamically via a form submission ( OnClick=AjaxFunction())

2) This works perfectly and retrieves the values from the form to process the ajax function and works just fine.

3) The particular element the ajax function requires is an id (e.g) <input type... id='id' value='<? echo $id; ?>'..

 

 

 

The Problem is..

1) I have a PHP loop which outputs multiple forms and they all must have this so called value (input type... id='id' value='<? echo $id; ?>'..

 

2) When i submit the form the ajax function just takes the first (or any) field value thats named id='id' value='<? echo $id; ?>

 

 

 

My Thoughts on how to fix this (But dont know how!)

1) During looping through the database and outputting the forms i want to not actually name any field id='id' value='<? echo $id; ?>'.. just yet

 

2) When the user submits one of the forms (as they are all the same) I want to then dynamically set THIS forms id='id' and value='<? echo $id; ?>'

 

 

 

So in other words

 

So, ill tell you where i am now, I have tried using Javascript to say something like onClick=myform.id.value='id' or something to that affect but there within lies a problem cos then i have to name all the forms 'myform' in the loop and when the onClick function happens it will just set all the fields cos all the forms are name the same which is why i need the javascrip to use THIS form attribute!

 

 

If this can be done with an OnClick function can i do it via an <a href> link from within the form or only via a <input type='submit'>??

 

 

 

 

I hope I've been as clear as I can, sorry if I havent im abit of a noob to this stuff and again any help or thoughts would be hugely welcome!

 

Thank you in advance,

 

Wayne.

  • Author

Many Thanks rallport for your reply,

 

I just got the issue sorted which is great, I am essentially a newb to Javascript so each time the database looped through a record it pumped out a form containing a hidden field called "id" with a unique databse id number as its value.

 

However what i couldnt figure out was when any of the outputted form was submitted how would the Ajax function know it was this form i was submitting to it.

 

Anyway the answer was in the question which I eventually found through alot of googling and the answer was so simple > onClick='ajaxFunction(this.form);return false'

 

Love it!

 

Many thanks to yourself rallport and all who took the time to read.

 

Wayne.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.