9 years ago
2
Topic

What is the best way to do the following:

I have a Form.  I need to construct the article title, article alias and a stock number based on the values input in 4 other fields.

To do this I can either add a button that invokes a javascript script, or it can be done just before submitting the form.

I tried to do this with a position override  ( ....admin/mainbody.php )  by including the script and button that invoked it  to update the fields
as below, but it didn't work. When I clicked my button  I was returned to the Content Manager screen (no content saved).

I tried to add the javascript to a field, but couldn't figure out just what was needed (used the "orange arrow"), or find documentation about this (e.g. do I need to have the <script> tags, what are the variable names at that point? )

What do I need to do this?  Is the code pack required to accomplish it?

Thanks in advance for any advice.

<?php

/**
* @package SD Simple Simon Template V2.5.0 for SEBLOD 3.x - www.seblod.com
* @license GNU General Public License version 2 or later
* @author Simon Dowdles - http://www.simondowdles.com
* @copyright Copyright (C) 2013 Simon Dowdles New Media Holdings (Pty) Ltd. All Rights Reserved.
**/

// No Direct Access
defined( '_JEXEC' ) or die;

echo "Title: ". $cck->renderField('art_title');
echo "Alias:".$cck->renderField('art_alias');
echo "Category:".$cck->renderField('art_catid');
echo "VIN:".$cck->renderField('test_vin');
echo "Year:".$cck->renderField('test_year');
echo "Model:".$cck->renderField('test_model');
echo "Make:".$cck->renderField('test_make');

?>
<button onclick="myFunction()">Click me</button>
<script>

function changeInput(element,value){
var opt = document.getElementById(element);
opt.value = value;
}
function changeWords(element,value) {
document.getElementById(element).innerHTML = value;
}
function myFunction() {

var y = document.getElementById("cck1r_label_test_year");
var e = document.getElementById("cck1r_label_test_make");
var evalue = e.options[e.selectedIndex].value;
var etext = e.options[e.selectedIndex].text;
var f = document.getElementById("model");
var fvalue = f.options[f.selectedIndex].value;
var ftext = f.options[f.selectedIndex].text;
var b = y.value +" "+etext+" "+ftext;
var v = document.getElementById("cck1r_label_test_veh_vin").value;
var vinlength = veh_vin.value.length;
var ls = vinlength-6;
var le =vinlength-1;
var vehstock = veh_vin.value.substr(ls,le);
changeInput("art_title",b);
changeInput("cck1r_label_test_veh_stock_number",vehstock);
changeInput("art_alias",v);
}
</script>

Get a Book for SEBLOD
84 Posts
Skepsis
9 years ago
1
Level 1

Hello,

I think this plugin will solve your problem.

Greetings
Skepsis

9 years ago
0
Level 2

Thanks Skepsis!   It looks like it will do almost all of what I wanted, except for being able to extract a substring from a field to concat/fill  another (rather than the whole field content.)   Great as is, and hoping to see the latter covered in an update.  I appreciate the suggestion.

Get a Book for SEBLOD