• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

onclick question

Guest
Jan 15, 2009 Jan 15, 2009

Copy link to clipboard

Copied

Hello Everyone,

I have a question regarding the onclick functionaility. Bascially, I have two different submit links. I have to insert data in different formats based on the link I click. This I am able to do separately. My problem is that I have to do this based on a prior condition. It is basically a entry form, and first I am checking if the form is not for edit purposes. I am doing something like below:

<cfif formedit eq 1>
<input type = "hidden name="editaction" value="edit">
<cfelse>
<input type="hidden" name="addaction" value="add">


<a href="hello.cfm" onClick="addform();return false;" <cfif editaction EQ 1>Save<cfelse>Add New Person.</cfif></a>

Currently I want to add a new link with a slight differently functionaily as add. Is there a way in coldfusion I can detect if whick link has been clicked and based upon that I can take appropriate action? I am not understanding how do i add something like below to the above code

<cfif formedit eq 1>
<input type = "hidden name="editaction" value="edit">
<cfelse>
<input type="hidden" name="addaction" value="add">
<cfelse>
<input type="hidden" name="adddiffaction" value="adddiff">

I hope I explained my question clearly and I would appreciate any hints or tips regarding this.

Thanks.

TOPICS
Advanced techniques

Views

809

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2009 Jan 15, 2009

Copy link to clipboard

Copied

I think it would be simpler to use url variables instead of onClick functions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 15, 2009 Jan 15, 2009

Copy link to clipboard

Copied

Hi,
I'm not sure I really understand what you are looking for but here's what I do when I want to use the same form to add or edit records:

The form gets either pre-filled with an existing record, or empty for new records. For existing records the record ID (primary key in the DB) is filled into a hidden field.

In the action script I can verify:

<cfif isnumeric(myhidden_record_field)>
<cfquery>
UPDATE table_something
set field1=x,
field2=y,
field3=z
WHERE PK= #my_hidden_record_field#
</cfquery>
<cfelse>
<cfquery>
INSERT into table_something
field1, field2, field3
VALUES
x,y,z
</cfquery>
</cfif>
So the data sent from the client to the server includes information if this is an existing record or a new record, and on server side you can process it accordingly. In this case it would not matter if the button is an update-button, or save- button.
This also allows you to simply build a copy-record feature if you need it (just empty the record field).

I think it may help you to evaluate in more detail what should happen SERVER-SIDE, and what should happen CLIENT-SIDE.

As example if you are talking about prior condition, I would expect on the server you would know about that condition, and could send the entry-form to the client already setup to be used as a edit-form OR a add-record-form.

cheers,
fober

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 22, 2009 Jan 22, 2009

Copy link to clipboard

Copied

LATEST
Hi,

Below is the detailed explanation of my problem


My application has two different users...

a) students

b) advisors.


When the advisor logs in, he has two links to navigate to

The first page has drop down menus of other advisors from which he can add permissions for some activities. In the second page, the advisor has a form with text fields where he has to enter the student details manually. Right now there is a <a href="index.cfm">Add student only for me</a>. That is when the advisors click the "add student only for me" , adds a new student, and i am retrieving the values and making them display in the page.

I am doing this as follows:

a) I am retreiving the student name as a link, so when the advisor wants to edit some information about the student , he can do so.

b) Initially, I am setting two values like

<cfset student_edit = 0>
<cfset student_add = 0>

so when the student name is clicked , i set the student_edit to 1, and have the following hidden values:

<cfif student_edit eq 1>
<input type = "hidden name="editaction" value="edit">
<cfelse>
<input type="hidden" name="addaction" value="add">

then i am creating my component object (by using <cfset saveobject = createObject(component.addstudent)>)and pass the required parameters like firstname, etc for saving the student details. There is a function called save_student() which requires parameters.

All this is working fine.

Recently, my prof asked me to add another link which says "Add student for all advisors". That is, the advisors he added in the previous page should also see these students in their students page. Currently What I am doing is as follow:


a) I created another anchor link saying "Add students for all advisors". I wrote a query to get the advisors whom the current advisor gave permissions to. Then I am getting their IDs from the database, and when I click the button, this particular student will get inserted for every advisor. So I write another function in the component to accomodate this change, which inserts this particular student for all the advisors. I am calling this function using the same component object I created above. Previously, because I coded that if its not an edit action, then add the student. Like below:

<a href="index.cfm" onClick="addform(1);return false;" <cfif editaction EQ 1>Save<cfelse>Add New Student.</cfif></a>. the addform() function is for validation purposes


I did not want to change the above code. So I wrote a javascript function like "addstudentforall()" in which I called the "add student to all advisors" function i wrote in the component, and used onclick to call the javascript function.
<a href="index.cfm" onClick="addstudentsforall();addform(1);return false;" <cfif editaction EQ 1>Save<cfelse>Add New Student for all.</cfif></a>.

Now, the problem I am facing.

When I do this separately, it works for individual links, but when I place the existing "add student for me" function above the new javascript function, both the links are showing the same functionailty that is both the links add the student only for the current advisor, and if I place the javascript function above the existing code, both the links add students for all the advisors. I have been going crazy on how to approach this. It would be great if you provide any suggestions and tell me if my approach is right.

I hope you understood my question.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation